package cc.sunni.api.controller.user.fallbacks;

import cc.sunni.api.controller.user.UserControllerApi;
import cc.sunni.common.utils.R;
import cc.sunni.common.utils.ResultEnum;
import cc.sunni.pojo.bo.UpdateUserInfoBO;
import cc.sunni.pojo.vo.AppUserVO;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Component
public class UserControllerFactoryFallback implements FallbackFactory<UserControllerApi> {

    @Override
    public UserControllerApi create(Throwable throwable) {
        return new UserControllerApi() {
            @Override
            public R getUserInfo(String userId) {
                return R.en(ResultEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public R getAccountInfo(String userId) {
                return R.en(ResultEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public R updateUserInfo(@Valid UpdateUserInfoBO updateUserInfoBO) {
                return R.en(ResultEnum.SYSTEM_ERROR_FEIGN);
            }

            @Override
            public R queryByIds(String userIds) {
                System.out.println("进入客户端（服务调用者）的降级方法");
                List<AppUserVO> publisherList = new ArrayList<>();
                return R.ok(publisherList);
            }
        };
    }
}
